<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>VisitCali.com</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Things to do and not do">
    <meta name="author" content="Jeremy Moyson">

    <!-- Le styles -->
    <link href="../bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="../css/visitcali.css" rel="stylesheet">
    <link href="../bootstrap/css/bootstrap-responsive.css" rel="stylesheet">

    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="bootstrap/js/html5shiv.js"></script>
    <![endif]-->
  </head>

  <body>
 <?php
    include("function.php");
    init_connect_db();
    if(isset($_GET['tips'])) {
              $id_tips = $_GET['tips'];
    } else {
        $id_tips = 1;
    }
    ?>
       <div class="container">
         <div class="masthead">
          <h1 class="muted">VisitCali.com
          <?php
	//Session a mettre en place
	$user_id = 0;
	$isAdmin = true;
	 session_start();
	if (isset($_SESSION['email']))
	{
	  if (isset($_SESSION['admin'])) {
	     echo ('<a href="user.php"  style="margin:5px" class="btn btn-primary btn-medium pull-right">User Administration</a>');
	  }
	  echo ('<a href="../logout_user.php" style="margin:5px" class="btn btn-primary btn-medium pull-right">Sign-out</a><small style="margin:10px;font-size:0.5em"class="pull-right">'.$_SESSION['email'].'</small>');
	} else {
	  echo ('<a href="#modalSignUp" data-toggle="modal" style="margin:5px" class="btn btn-primary btn-medium pull-right">Sign up</a>');
	  echo ('<a href="#modalLogIn" data-toggle="modal" style="margin:5px" class="btn btn-primary btn-medium pull-right">Log in</a>');
	}
	?></h1>
          <img src="../img/widescreenBanner1.jpg" alt="smiley face"/> 
          <div class="navbar">
            <div class="navbar-inner">
              <div class="container">
                <ul class="nav">
                  <li><a href="../index.php">Home</a></li>
                  <li><a href="places.php">Places to visit</a></li>
                  <li class="active"><a href="dos-donts.php">Do's and don'ts</a></li>
                  <li><a href="faq.php">FAQ</a></li>
                  <li><a href="about.php">About us</a></li>
                </ul>
              </div>
            </div>
          </div>
        </div>
      
      
        <div class="row-fluid">
        <div class="span3">
         <?php
                  $result = get_dos_donts_city(1);
                   while($city_tips = mysql_fetch_array( $result )) {
                    echo ('<h2 style="text-align: center">'.$city_tips['city'].'</h2>');
                    $resulttips = get_dos_donts_city_type($city_tips['city'], 1);
                    echo ('<ul class="nav nav-tabs nav-stacked">');
                    while($tips = mysql_fetch_array( $resulttips )) {
                      echo('<li><a href="?tips='.$tips['id'].'"><i class="icon-thumbs-up"></i> '.$tips['title'].'</a></li>');
                    }
                    echo ('</ul>');
                   }
          ?>
      
        </div>
         <div class="span6">
          <div id="presDosDonts" class="tipsShow" >
            <?php
                  $result = get_dos_donts_from_id($id_tips);
                  while($tips = mysql_fetch_array( $result )) {
                    echo ('
                          <h3>'.$tips['title'].'</h3>
                          <p>'.$tips['article'].'</p>
                          ');
                  }
          
          ?>
        </div>
        </div>
         <div class="span3">
          <?php
          if (isset($_SESSION['admin']))
              {
                if ($_SESSION['admin'] ==  1) {
                echo ('
             <div class="span1">
              <a  href="#addNewTips" role="button" class="btn pull-right" data-toggle="modal"><i class="icon-plus"></i>&zwj;</a>
          </div>');
                }
              }
                   $result = get_dos_donts_city(0);
                  while($city_tips = mysql_fetch_array( $result )) {
                    $resulttips = get_dos_donts_city_type($city_tips['city'], 0);
                    echo ('<h2 style="text-align: center">'.$city_tips['city'].'</h2>');
                    echo ('<ul class="nav nav-tabs nav-stacked">');
                    while($tips = mysql_fetch_array( $resulttips )) {
                      echo('<li><a href="?tips='.$tips['id'].'"><i class="icon-thumbs-down"></i> '.$tips['title'].'</a></li>');
                    }
                    echo ('</ul>');
                   }
          ?>
        </div>
        </div>
      <hr>
        <div id="addNewTips" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>Add a new Tips</h3>
          </div>
           <form action="add_new_tips.php" method="post">
          <div class="modal-body">
             <?php
             echo '<input type="number" style="display: none" name="userId" value="'.$_SESSION['id'].'" />';
             ?>
             <select name="city" id="city">
             <?php
                   $result = get_dos_donts_city(0);
                  while($city_tips = mysql_fetch_array( $result )) {
                    echo ('
                          <option>'.$city_tips['city'].'</option>
                          ');
                  }
              ?>
            </select><br />
             <label class="radio">
              <input type="radio" name="type" id="optionsRadios1" value="1" checked>
              <i class="icon-thumbs-up"></i>
            </label>
            <label class="radio">
              <input type="radio" name="type" id="optionsRadios2" value="0">
                <i class="icon-thumbs-down"></i>
            </label>
             <input name="title" type="text" placeholder="Title" /><br />
            <textarea name="article" type="text" class="span5" rows="6"></textarea>
              <input class="btn" type="submit" name="submit" value="Submit" />
          </form>
          </div>
          <div class="modal-footer">
            <a href="#" data-dismiss="modal" aria-hidden="true" class="btn">Close</a>
          </div>
        </div>
        
          <div id="modalLogIn" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>Log in:</h3>
          </div>
           <form action="../login_user.php" method="post">
          <div class="modal-body">
	    <input class="span3" type="email" name="email" placeholder="E-mail" /><br />
	    <input class="span3" type="password" name="password" placeholder="Password" /><br />
              <input class="btn" type="submit" name="submit" value="Submit" />
          </form>
          </div>
          <div class="modal-footer">
            <a href="#" data-dismiss="modal" aria-hidden="true" class="btn">Close</a>
          </div>
        </div>
	
	
    <div id="modalSignUp" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>Create a account:</h3>
          </div>
           <form action="../add_user.php" method="post">
          <div class="modal-body">
            <input class="span3" type="text" name="firstname" placeholder="Firstname" /><br />
	    <input class="span3" type="text" name="lastname" placeholder="Lastname" /><br />
	    <input class="span3" type="email" name="email" placeholder="E-mail" /><br />
	    <input class="span3" type="password" name="password" placeholder="Password" /><br />
	    <input class="span3" type="text" name="dob" placeholder="Date of Birth AAAA-MM-JJ" /><br />
              <input class="btn" type="submit" name="submit" value="Submit" />
          </form>
          </div>
          <div class="modal-footer">
            <a href="#" data-dismiss="modal" aria-hidden="true" class="btn">Close</a>
          </div>
        </div>
       
      <div class="footer">
        <p>&copy; Company 2013</p>
      </div>

    </div>
    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="../bootstrap/js/jquery.js"></script>
    <script src="../bootstrap/js/bootstrap-transition.js"></script>
    <script src="../bootstrap/js/bootstrap-modal.js"></script>
    <script>
       function toogleTips(id) {
      $(".tipsShow").hide();
      $(".tipsShow").addClass("tipsHide");
      $(".tipsShow").removeClass("tipsShow");
      $("#"+id).show();
      $("#"+id).addClass("tipsShow");
      $("#"+id).removeClass("tipsHide");
    }
    </script>
  </body>
</html>
